// test_css3_values.js
// by SWC
// entry_function: start_css3_values_test()

var prefixes="-webkit- -moz- -o- -ms- ".split(" "),
			domPrefixes="webit moz o ms".split(" "),
			modElem=document.createElement("mod"),
			mStyle=modElem.style,
			docElement = document.documentElement;
	
	/**
     * testProps is a generic CSS / DOM property test; if a browser supports
     *   a certain property, it won't return undefined for it.
     *   A supported CSS property returns empty string when its not yet set.
     */
function testProps( props, prefixed ) {
	for ( var i in props ) {
		if ( mStyle[ props[i] ] !== undefined ) {
			return prefixed == 'pfx' ? props[i] : true;
		}
	}
	return false;
}

/**
 * testPropsAll tests a list of DOM properties we want to check against.
 *   We specify literally ALL possible (known and/or likely) properties on
 *   the element including the non-vendor prefixed one, for forward-
 *   compatibility.
 */
function testPropsAll( prop, prefixed ) {
	var ucProp  = prop.charAt(0).toUpperCase() + prop.substr(1),
		props   = (prop + ' ' + domPrefixes.join(ucProp + ' ') + ucProp).split(' ');
	return testProps(props, prefixed);
}
//is returns a boolean for if typeof obj is exactly type.
function is( obj, type ) {
	return typeof obj === type;
}   
// contains returns a boolean for if substr is found within str.
function contains( str, substr ) {
	return !!~('' + str).indexOf(substr);
}
 // setCss applies given styles to the Modernizr DOM node
function setCss( str ) {
	mStyle.cssText = str;
}
 // setCssAll extrapolates all vendor-specific css strings
function setCssAll( str1, str2 ) {
	return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
}

function Supported_values_color(para,name1,name2) {
	setCss('background-color:'+para+';');
	if(contains(mStyle.cssText, name1)||contains(mStyle.cssText, para)||contains(mStyle.cssText, name2))
		return true;
	else
		return false;
}

function Supported_values(para1,para2,name){
	setCss(para1+para2+';');
	if(contains(mStyle.cssText, name)||(contains(mStyle.cssText, para2)&&para2!==''))
		return true;
	else
		return false;
}

function Supported_values_other(para,name){
	setCss(para)
	if(contains(mStyle.cssText, name)||contains(mStyle.cssText, para))
		return true;
	return false;
}
function lineargradientSupported() {
	var str1 = 'background-image:',
		str2 = 'gradient(linear,0% 0%,0% 100%,from(#09C),to(#FCF));',
		str3 = 'linear-gradient(0% 0%,#09C,#FCF);';
	setCss((str1 + prefixes.join(str2 + str1) + prefixes.join(str3 + str1)).slice(0, -str1.length));
	return contains(mStyle.backgroundImage, 'gradient');
};

function gradientSupported(name,para) {
	var str1 = 'background-image:',
		str3 = name+para;
	setCss((str1+ prefixes.join(str3 + str1)).slice(0, -str1.length));
	return contains(mStyle.backgroundImage, 'gradient');
};

function result_test(result){
	//TODO replace with sandbox

	result["values_color"] = {
		layerName:	"Color",
		type:"aggrg",
		nlist: {
			"RGBA": Supported_values_color('rgba(150,255,150,.5)','rgba'),
			"HSLA": Supported_values_color('hsla(360,50%,50%,0.5)','hsla','rgba'),
			"HSL": Supported_values_color('hsl(360,50%,50%)','hsl','rgb'),
			"transparent": Supported_values_color('transparent','transparent')
		}
	};
	
	result["values_other"] = {
		layerName:	"Others",
		type:"aggrg",
		nlist: {
			"line-height": Supported_values('line-height:','1.5','Number'),
			"Z-index": Supported_values('z-index:','10','Integer'),
			"Angel": Supported_values_other('-moz-transform:rotate(2deg);-webkit-transform:rotate(2deg);-o-transform:rotate(2deg);-ms-transform:rotate(2deg);transform:rotate(2deg);','deg')&&Supported_values_other('-moz-transform:rotate(2grad);-webkit-transform:rotate(2grad);-o-transform:rotate(2grad);-ms-transform:rotate(2grad);transform:rotate(2grad);','grad')&&Supported_values_other('-moz-transform:rotate(2rad);-webkit-transform:rotate(2rad);-o-transform:rotate(2rad);-ms-transform:rotate(2rad);transform:rotate(2rad);','rad')&&Supported_values_other('-moz-transform:rotate(.5turn);-webkit-transform:rotate(.5turn);-o-transform:rotate(.5turn);-ms-transform:rotate(2grad);transform:rotate(.5turn);','turn'),
			"Time": Supported_values_other('-moz-transition-duration:.5s;-webkit-transition-duration:.5s;-o-transition-duration:.5s;-ms-transition-duration:.5s;transition-duration:.5s;','s')&&Supported_values_other('-moz-transition-duration:50ms;-webkit-transition-duration:50ms;-o-transition-duration:50ms;-ms-transition-duration:50ms;transition-duration:50ms;','ms'),
			"Frequency":Supported_values_other('pitch: 75hz;','hz')&&Supported_values_other('pitch: 0.5khz;','khz'),
			"Fraction":Supported_values_other('border-parts:10px 1fr 10px;','fr'),
			"grid":Supported_values('float-offset:2','gr','Grid'),
			"clac()":Supported_values_other('width:-moz-calc(100% - 50px);width:calc(100% - 50px);width:-o-calc(100% - 50px);-webkit-width:calc(100% - 50px);-ms-width:calc(100% - 50px);','width'),
			"min()":Supported_values_other('width:min(10% + 20px, 300px);}','width'),
			"max()":Supported_values_other('width:max(10% + 20px, 300px);}','width'),
			"linear-gradient":lineargradientSupported(),
			"radial-gradient":gradientSupported('radial','-gradient(circle contain,#f00,#ff0,#080);'),
			"repeating-linear-gradient":gradientSupported('repeating-linear','-gradient(0deg,#f00,#ff0 10%,#f00 15%);'),
			"repeating-radial-gradient":gradientSupported('repeating-radial','-gradient(circle,#f00 0,#ff0 10%,#f00 15%);')
		}
	};
}


function start_css3_values_test(container){
	var E = {
		layerName: "CSS3 Values",
		type: "aggrg",
		nlist: {}
	};
	result_test(E.nlist);
	return E;
}
	